package com.sky.config.mvc;

import com.sky.module.suppot.file.s3.OssProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

/**
 * @author
 * @date 2023/3/2 16:13
 **/
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {
    @Autowired
    private OssProperties ossProperties;







    // 进行资源的映射
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        String path1 = ossProperties.getPath();
        // 决定路径
        String path = new File(path1).getAbsolutePath() + "\\";
        final String bucketName = ossProperties.getBucketName();
//        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        //上传的图片在D盘下的OTA目录下，访问路径如：http://localhost:8081/OTA/d3cf0281-bb7f-40e0-ab77-406db95ccf2c.jpg
        //其中OTA表示访问的前缀。"file:D:/OTA/"是文件真实的存储路径
//        path
        registry.addResourceHandler("/sky/**").addResourceLocations("file:" + path);
//        registry.addResourceHandler("/upload02/**").addResourceLocations("file:C:/upload02/");
//        registry.addResourceHandler("/")
    }
}
